import os

from flask import Flask,render_template
import pandas as pd
import numpy as np
from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
from pyecharts.globals import SymbolType
from pyecharts.components import Table
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
from pyecharts.globals import SymbolType
from pyecharts.globals import ChartType
from pyecharts.globals import CurrentConfig
CurrentConfig.ONLINE_HOST ='static/'
import textwrap

# 自定义排序函数
def custom_sort(guimo):
    sort_rule = [('20人以下',0),('20-99人',1), ('100-299人',2), ('300-499人',3), ('500-999人',4), ('1000-9999人',5),('10000人以上',6)]
    sort_ls = []
    for i in guimo:
        for rule in sort_rule:
            if rule[0] in i:
                sort_ls.append((rule[1], i))
                break
    sort_ls.sort()
    return [i[1] for i in sort_ls]

def bar_chart(desc, title_pos):
    df_t = data1[(data1['城市'] == desc)&(data1['地点'] != desc)]['地点'].value_counts().sort_values(ascending = False).reset_index()
    df_t.columns = [desc,'岗位需求量']
    df_t[desc] = df_t[desc].apply(lambda x:x.split('-')[1])
    # 新建一个Bar
    chart = Bar(
        init_opts=opts.InitOpts(
            # bg_color='#2C3B4C',  # 设置背景颜色
            theme='white',         # 设置主题
            width='400px',     # 设置图的宽度
            height='400px'
        )
    )
    chart.add_xaxis(
        df_t[desc].tolist()
    )
    chart.add_yaxis(
        '',
        df_t['岗位需求量'].tolist()
    )
    chart.set_series_opts( # 自定义图表样式
        label_opts=opts.LabelOpts(
            is_show=True,
            position='top', # position 标签的位置 可选 'top'，'left'，'right'，'bottom'，'inside'，'insideLeft'，'insideRight'
            font_size=15,
            color= '#727F91',
            font_weight = 'bolder',  # font_weight 文字字体的粗细  'normal'，'bold'，'bolder'，'lighter'
            font_style = 'oblique',  # font_style 文字字体的风格，可选 'normal'，'italic'，'oblique'
            ), # 是否显示数据标签
        itemstyle_opts={
            "normal": {
                'shadowBlur': 10,   # 光影大小
                "barBorderRadius": [100, 100, 0, 0],  # 调整柱子圆角弧度
                "shadowColor": "#94A4B4", # 调整阴影颜色
                'shadowOffsetY': 6,
                'shadowOffsetX': 6,  # 偏移量
            }
        }
    )
    # Bar的全局配置项
    chart.set_global_opts(
        xaxis_opts=opts.AxisOpts(
            name='地区',
            is_scale=True,
            axislabel_opts=opts.LabelOpts(rotate = 45),
            # 网格线配置
            splitline_opts=opts.SplitLineOpts(
                is_show=False,
                linestyle_opts=opts.LineStyleOpts(
                    type_='dashed'))
        ),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            name='岗位需求量',
            type_="value",
            # 网格线配置
            splitline_opts=opts.SplitLineOpts(
                is_show=False,
                linestyle_opts=opts.LineStyleOpts(
                    type_='dashed'))
        ),
        # 标题配置
        title_opts=opts.TitleOpts(
            title=desc,
            pos_left=title_pos[0],
            pos_top=title_pos[1],
            title_textstyle_opts=opts.TextStyleOpts(color='#2C3B4C', font_size=20)
        ),
        tooltip_opts=opts.TooltipOpts(
            is_show=True,  # 是否使用提示框
            trigger='axis',  # 触发类型
            # is_show_content = True,
            trigger_on='mousemove|click',  # 触发条件，点击或者悬停均可出发
            axis_pointer_type='cross',  # 指示器类型，鼠标移动到图表区可以查看效果
        ),
    )
    return chart
# 绘制圆角柱状图函数
def echarts_bar1(x,y,title = '主标题',subtitle = '副标题',label = '图例'):
    """
    x: 函数传入x轴标签数据
    y：函数传入y轴数据
    title：主标题
    subtitle：副标题
    label：图例
    """
    bar = Bar(
            init_opts=opts.InitOpts(
            theme='shine',
            width='1000px',
            height='700px'
        )
    )
    bar.add_xaxis(x)
    bar.add_yaxis(label,y,
        label_opts=opts.LabelOpts(is_show=True)
        ,category_gap="50%"
        )
    bar.reversal_axis()
    bar.set_series_opts(
        label_opts=opts.LabelOpts(
            is_show=True,
            position='right',
            font_size=15,
            color= '#333333',
            font_weight = 'bolder',
            font_style = 'oblique',
            ),
        itemstyle_opts={
            "normal": {
                "color": JsCode(
                    """new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,color: '#FC7D5D'}
                        ,{offset: 1,color: '#C45739'}], false)
                    """
                ),
                'shadowBlur': 6,
                "barBorderRadius": [100, 100, 100, 100],
                "shadowColor": "#999999",
                'shadowOffsetY': 2,
                'shadowOffsetX': 2,
            }
        }
    )
    bar.set_global_opts(
        title_opts=opts.TitleOpts(
            title=title,
            subtitle=subtitle,
            pos_left='center',
            title_textstyle_opts=opts.TextStyleOpts(color='#2C3B4C', font_size=20,font_weight='bolder')
        ),
        legend_opts=opts.LegendOpts(
            is_show=True,
            pos_left='right',
            pos_top='3%',
            orient='horizontal'
        ),
        tooltip_opts=opts.TooltipOpts(
            is_show=True,
            trigger='axis',
            trigger_on='mousemove|click',
            axis_pointer_type='cross',
        ),
        yaxis_opts=opts.AxisOpts(
            is_show=True,
            splitline_opts=opts.SplitLineOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(
                font_size=13,
                font_weight='bolder'
            ),
        ),
        xaxis_opts=opts.AxisOpts(
            boundary_gap=True,
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_show=True),
            axislabel_opts=opts.LabelOpts(
                font_size=13,
                font_weight='bolder'
            ),
        ),
    )
    return bar

def bar_chart4(x,y,title_pos,title = '主标题',subtitle = '副标题'):
    # 新建一个Bar
    chart = Bar(
        init_opts=opts.InitOpts(
            # bg_color='#2C3B4C',  # 设置背景颜色
            theme='white',         # 设置主题
            width='400px',     # 设置图的宽度
            height='400px'
        )
    )
    chart.add_xaxis(
        x
    )
    chart.add_yaxis(
        '',
        y
    )
    chart.set_series_opts( # 自定义图表样式
        label_opts=opts.LabelOpts(
            is_show=True,
            position='top', # position 标签的位置 可选 'top'，'left'，'right'，'bottom'，'inside'，'insideLeft'，'insideRight'
            font_size=15,
            color= '#727F91',
            font_weight = 'bolder',  # font_weight 文字字体的粗细  'normal'，'bold'，'bolder'，'lighter'
            font_style = 'oblique',  # font_style 文字字体的风格，可选 'normal'，'italic'，'oblique'
            ), # 是否显示数据标签
        itemstyle_opts={
            "normal": {
                'shadowBlur': 10,   # 光影大小
                "barBorderRadius": [100, 100, 0, 0],  # 调整柱子圆角弧度
                "shadowColor": "#94A4B4", # 调整阴影颜色
                'shadowOffsetY': 6,
                'shadowOffsetX': 6,  # 偏移量
            }
        }
    )
    # Bar的全局配置项
    chart.set_global_opts(
        xaxis_opts=opts.AxisOpts(
            name=' ',
            is_scale=True,
            axislabel_opts=opts.LabelOpts(rotate = 45),
            # 网格线配置
            splitline_opts=opts.SplitLineOpts(
                is_show=False,
                linestyle_opts=opts.LineStyleOpts(
                    type_='dashed'))
        ),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            name='薪资均值',
            type_="value",
            # 网格线配置
            splitline_opts=opts.SplitLineOpts(
                is_show=False,
                linestyle_opts=opts.LineStyleOpts(
                    type_='dashed'))
        ),
        # 标题配置
        title_opts=opts.TitleOpts(
            title=title,
            subtitle = subtitle,
            pos_left=title_pos[0],
            pos_top=title_pos[1],
            title_textstyle_opts=opts.TextStyleOpts(color='#2C3B4C', font_size=20)
        ),
        tooltip_opts=opts.TooltipOpts(
            is_show=True,  # 是否使用提示框
            trigger='axis',  # 触发类型
            # is_show_content = True,
            trigger_on='mousemove|click',  # 触发条件，点击或者悬停均可出发
            axis_pointer_type='cross',  # 指示器类型，鼠标移动到图表区可以查看效果
        ),
    )
    return chart

# 定义函数将薪资转化为数字形式
def salary_handle(word):
        if word[-1] == '万':
            num = float(word.strip('万')) * 10000
        elif word[-1] == '千':
            num = float(word.strip('千')) * 1000
        return num




data = pd.read_csv('2022年数据分析岗招聘数据.csv',encoding='utf-8')
data['公司规模'] = data['公司规模'].fillna("无")
data['城市'] = data['地点'].apply(lambda x: x.split('-')[0])
data1 = data[data['薪资范围'] != '面议']
data1 = data1[~data1.薪资范围.str.contains('/天')]
data1 = data1[~data1.薪资范围.str.contains('以下')]
data1['薪资下限'] = data1.薪资范围.apply(lambda x: x.split('-')[0])
data1['薪资上限'] = data1.薪资范围.apply(lambda x: x.split('-')[1])



data1['薪资下限'] = data1.薪资下限.apply(lambda x: salary_handle(x))
data1['薪资上限'] = data1.薪资上限.apply(lambda x: salary_handle(x))
data1['薪资均值'] = round((data1.薪资上限 + data1.薪资下限) / 2, 2)
data1 = data1.reset_index(drop=True)
data1 = data1.drop(index=5860)
data1.to_excel(excel_writer="data1.xlsx", index=False, encoding='utf-8')
data1 = pd.read_excel('data1.xlsx')
cities = list(data1['城市'].unique())
cities_count = list(data1['城市'].value_counts())
# 合并列表
zipped = zip(cities, cities_count)
urban = [list(z) for z in zipped]



app = Flask(__name__)


@app.route('/')
def home():

    return render_template('home.html')
@app.route('/index')
def  index():
    return render_template('index.html')

@app.route('/view1')
def view1():
    return render_template('view1.html')

@app.route('/view1_1')
def view1_1():

    c = (
        Geo()
            .add_schema(maptype="china")
            .add(
            "岗位需求地区分布", urban,
            type_=ChartType.HEATMAP,
        )
            .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(
                max_=1000,
                min_=0,
                is_piecewise=True,
                split_number=4,
            ),
            title_opts=opts.TitleOpts(
                title="岗位需求量——城市分布"
            )
        )
    )
    c.render('templates/view1_1.html')

    return render_template('view1_1.html')

@app.route('/view1_2')
def view1_2():
    c = (
        Geo()
            .add_schema(maptype="china")
            .add(
            "岗位需求数量",
            urban,
            type_=ChartType.EFFECT_SCATTER,
        )
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
            .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(
                max_=1000,
                min_=0,
                is_piecewise=True,
                split_number=4,
                range_color=['#869d9d', '#a35c8f', '#a7535a'],
            ),
            title_opts=opts.TitleOpts(
                title="具体城市岗位需求数量"
            )
        ).render('templates/view1_2.html')

    )

    return render_template('view1_2.html')


@app.route('/view2')
def view2():
    return render_template('view2.html')


@app.route('/view2_1')
def view2_1():
    job_demand = data1.城市.value_counts().sort_values(ascending=True)
    echarts_bar1(job_demand.index.tolist(), job_demand.values.tolist(), title='全国各地数据分析岗岗位需求排名', subtitle=' ',
                 label='岗位需求量').render('templates/view2_1.html')
    return render_template('view2_1.html')



@app.route('/view2_2')
def view2_2():
    # 北上广深和成都杭州各个地区岗位需求量
    beijing_demand = data[data['城市'] == '北京']['地点'].value_counts().sort_values(ascending=False)
    shanghai_demand = data[data['城市'] == '上海']['地点'].value_counts().sort_values(ascending=False)
    shenzhen_demand = data[data['城市'] == '深圳']['地点'].value_counts().sort_values(ascending=False)
    guangzhou_demand = data[data['城市'] == '广州']['地点'].value_counts().sort_values(ascending=False)
    chengdu_demand = data[data['城市'] == '成都']['地点'].value_counts().sort_values(ascending=False)
    hangzhou_demand = data[data['城市'] == '杭州']['地点'].value_counts().sort_values(ascending=False)
    grid = Grid(
        init_opts=opts.InitOpts(
            theme='white',
            width='1200px',
            height='1200px',
        )
    )
    # 依次添加不同属性下价格对比Bar
    grid.add(
        bar_chart('北京', ['15%', '6%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='10%',  # 指定Grid中子图的位置
            pos_bottom='70%',
            pos_left='5%',
            pos_right='70%'
        )
    )
    grid.add(
        bar_chart('上海', ['50%', '6%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='10%',
            pos_bottom='70%',
            pos_left='40%',
            pos_right='35%'
        )
    )
    grid.add(
        bar_chart('广州', ['85%', '6%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='10%',
            pos_bottom='70%',
            pos_left='75%',
            pos_right='0%'
        )
    )
    grid.add(
        bar_chart('深圳', ['15%', '38%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='40%',
            pos_bottom='40%',
            pos_left='5%',
            pos_right='70%'
        )
    )
    grid.add(
        bar_chart('成都', ['50%', '38%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='40%',
            pos_bottom='40%',
            pos_left='40%',
            pos_right='35%'
        )
    )
    grid.add(
        bar_chart('杭州', ['85%', '38%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='40%',
            pos_bottom='40%',
            pos_left='75%',
            pos_right='0%'
        )
    )
    grid.add(
        bar_chart('武汉', ['15%', '68%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='70%',
            pos_bottom='10%',
            pos_left='5%',
            pos_right='70%'
        )
    )
    grid.add(
        bar_chart('南京', ['50%', '68%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='70%',
            pos_bottom='10%',
            pos_left='40%',
            pos_right='35%'
        )
    )
    grid.add(
        bar_chart('郑州', ['85%', '68%']),
        # is_control_axis_index=False,
        grid_opts=opts.GridOpts(
            pos_top='70%',
            pos_bottom='10%',
            pos_left='75%',
            pos_right='0%'
        )
    )
    grid.render('templates/view2_2.html')
    return render_template('view2_2.html')




@app.route('/view3')
def view3():
    return render_template('view3.html')



@app.route('/view3_1')
def view3_1():
    pie1 = data1[['工作经验', '职位名称']].groupby('工作经验').count().sort_values(by='职位名称', ascending=False).reset_index()
    pie1 = (Pie()
        .add('', [list(z) for z in zip(pie1['工作经验'], pie1['职位名称'])])
        .set_global_opts(
        title_opts=opts.TitleOpts(
            title='工作经验要求',
            title_textstyle_opts=opts.TextStyleOpts(color='#2C3B4C', font_size=20)
        )
    )
    )
    pie1.render('templates/view3_1.html')
    return render_template('view3_1.html')




@app.route('/view3_2')
def view3_2():
    degree = data1[["学历要求"]]
    degree = data1['学历要求'].value_counts().reset_index(name='数量').rename(columns={"index": "学历要求"}).sort_values(by='数量',                                                                                                        ascending=False)
    x = degree['学历要求']
    y = degree['数量']
    x1 = list(x)
    y1 = list(y)
    学历要求 = x1
    num = y1
    color_series = ['#FAE927', '#E9E416', '#C9DA36', '#9ECB3C', '#6DBC49',
                    '#37B44E', '#3DBA78'
                    ]

    df = pd.DataFrame({'学历要求': 学历要求, 'num': num})
    df.sort_values(by='num', ascending=False, inplace=True)
    v = df['学历要求'].values.tolist()
    d = df['num'].values.tolist()
    pie2 = Pie(init_opts=opts.InitOpts(width='950px', height='800px'))
    pie2.set_colors(color_series)



    pie2.add("", [list(z) for z in zip(v, d)],
             radius=["50%", "130%"],
             center=["50%", "65%"],
             rosetype="area"
             )
    pie2.set_global_opts(title_opts=opts.TitleOpts(title='学历要求次数玫瑰图',
                                                   title_textstyle_opts=opts.TextStyleOpts(font_size=20,
                                                                                           color='#0085c3'),
                                                   subtitle_textstyle_opts=opts.TextStyleOpts(font_size=40,
                                                                                              color='#003399'),
                                                   pos_right='center', pos_left='center', pos_top='60%',
                                                   pos_bottom='center'
                                                   ),
                         legend_opts=opts.LegendOpts(is_show=False),
                         toolbox_opts=opts.ToolboxOpts())
    pie2.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="inside", font_size=12,
                                                   formatter="{b}:{c}次", font_style="italic",
                                                   font_weight="bold", font_family="Microsoft YaHei"
                                                   ),
                         )

    pie2.render('templates/view3_2.html')
    return render_template('view3_2.html')


@app.route('/view3_3')
def view3_3():
    tag_array = data1['岗位标签'].apply(lambda x: eval(x)).tolist()
    tag_lis = []
    for tag in tag_array:
        tag_lis += tag
    tag_df = pd.DataFrame(tag_lis, columns=['职位标签'])
    tag_df_cnt = tag_df['职位标签'].value_counts().reset_index()
    tag_df_cnt.columns = ['职位标签', '计数']
    word_cnt_lis = [tag for tag in zip(tag_df_cnt['职位标签'], tag_df_cnt['计数'])]
    wc = (
        WordCloud()
            .add("",
                 word_cnt_lis,
                 )
            .set_global_opts(
            title_opts=opts.TitleOpts(title="岗位标签词云图"),
        )
    )

    wc.render('templates/view3_3.html')
    return render_template('view3_3.html')


@app.route('/view4')
def view4():
    return  render_template('view4.html')


@app.route('/view4_1')
def view4_1():
    city_salary = data1[['城市', '薪资均值']].groupby('城市').mean().round(0).sort_values(by='薪资均值',ascending=True).reset_index()
    x = city_salary['城市']
    x1 = list(x)

    y = city_salary['薪资均值']
    y1 = list(y)

    data = [[x1[i], y1[i]] for i in range(len(x1))]
    (
        Funnel(init_opts=opts.InitOpts(width="1000px", height="700px"))
            .add(
            series_name="",
            data_pair=data,
            gap=2,
            tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{a} <br/>{b} : {c}"),
            label_opts=opts.LabelOpts(is_show=True, position="inside"),
            itemstyle_opts=opts.ItemStyleOpts(border_color="#fff", border_width=6),
        )
            .set_global_opts(title_opts=opts.TitleOpts(title="", subtitle="全国各地薪资均值"))
            .render('templates/view4_1.html')
    )
    return render_template('view4_1.html')

@app.route('/view4_2')
def view4_2():
    # 不同学历、不同经验、大专-不同经验交叉分析、本科-不同经验交叉分析、硕士-不同经验交叉分析、学历不限-不同经验交叉分析
    job_exp = data1[['工作经验', '薪资均值']].groupby('工作经验').mean().round(0).sort_values(by='薪资均值',
                                                                                  ascending=False).reset_index()
    job_edu = data1[['学历要求', '薪资均值']].groupby('学历要求').mean().round(0).sort_values(by='薪资均值',
                                                                                  ascending=False).reset_index()
    benke_exp = data1[data1['学历要求'] == '本科'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    dazhuan_exp = data1[data1['学历要求'] == '大专'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    shuoshi_exp = data1[data1['学历要求'] == '硕士'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    buxian_exp = data1[data1['学历要求'] == '学历不限'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    boshi_exp = data1[data1['学历要求'] == '博士'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    gaozhong_exp = data1[data1['学历要求'] == '高中'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    zhongzhuan_exp = data1[data1['学历要求'] == '中专/中技'][['工作经验', '薪资均值']].groupby('工作经验').mean().round(0). \
        sort_values(by='薪资均值', ascending=False).reset_index()
    grid = Grid(
        init_opts=opts.InitOpts(
            theme='white',
            width='1200px',
            height='1200px',
        )
    )
    # 依次添加不同属性下价格对比Bar
    grid.add(
        bar_chart4(job_exp['工作经验'].tolist(), job_exp['薪资均值'].tolist(), ['10%', '8%'], title='不同工作经验薪资对比',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='10%',  # 指定Grid中子图的位置
            pos_bottom='70%',
            pos_left='5%',
            pos_right='70%'
        )
    )
    grid.add(
        bar_chart4(job_edu['学历要求'].tolist(), job_edu['薪资均值'].tolist(), ['48%', '8%'], title='不同学历要求薪资对比',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='10%',
            pos_bottom='70%',
            pos_left='40%',
            pos_right='35%'
        )
    )
    grid.add(
        bar_chart4(buxian_exp['工作经验'].tolist(), buxian_exp['薪资均值'].tolist(), ['85%', '8%'], title='学历不限',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='10%',
            pos_bottom='70%',
            pos_left='75%',
            pos_right='0%'
        )
    )
    grid.add(
        bar_chart4(dazhuan_exp['工作经验'].tolist(), dazhuan_exp['薪资均值'].tolist(), ['15%', '40%'], title='大专',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='40%',
            pos_bottom='40%',
            pos_left='5%',
            pos_right='70%'
        )
    )
    grid.add(
        bar_chart4(benke_exp['工作经验'].tolist(), benke_exp['薪资均值'].tolist(), ['50%', '40%'], title='本科',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='40%',
            pos_bottom='40%',
            pos_left='40%',
            pos_right='35%'
        )
    )
    grid.add(
        bar_chart4(shuoshi_exp['工作经验'].tolist(), shuoshi_exp['薪资均值'].tolist(), ['85%', '40%'], title='硕士',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='40%',
            pos_bottom='40%',
            pos_left='75%',
            pos_right='0%'
        )
    )
    grid.add(
        bar_chart4(boshi_exp['工作经验'].tolist(), boshi_exp['薪资均值'].tolist(), ['15%', '70%'], title='博士',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='70%',
            pos_bottom='10%',
            pos_left='5%',
            pos_right='70%'
        )
    )
    grid.add(
        bar_chart4(gaozhong_exp['工作经验'].tolist(), gaozhong_exp['薪资均值'].tolist(), ['50%', '70%'], title='高中',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='70%',
            pos_bottom='10%',
            pos_left='40%',
            pos_right='35%'
        )
    )
    grid.add(
        bar_chart4(zhongzhuan_exp['工作经验'].tolist(), zhongzhuan_exp['薪资均值'].tolist(), ['85%', '70%'], title='中专/中技',
                   subtitle=' '),
        grid_opts=opts.GridOpts(
            pos_top='70%',
            pos_bottom='10%',
            pos_left='75%',
            pos_right='0%'
        )
    )
    grid.render('templates/view4_2.html')
    return  render_template('view4_2.html')









@app.route('/view5')
def view5():
    return  render_template('view5.html')


@app.route('/view5_1')
def view5_1():
    leixing = list(data1['公司类型'].unique())
    leixing_count = list(data1['公司类型'].value_counts())

    c = (
        Pie(init_opts=opts.InitOpts(width="800px", height="600px"))
            .add(
            series_name="公司类型",
            data_pair=[list(z) for z in zip(leixing, leixing_count)],
            radius=["50%", "70%"],
            label_opts=opts.LabelOpts(is_show=True, ),
        )
            .set_global_opts(legend_opts=opts.LegendOpts(pos_left="legft", orient="vertical"))
            .set_series_opts(
            tooltip_opts=opts.TooltipOpts(
                trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"
            ),
        )
    )
    c.render('templates/view5_1.html')
    return  render_template('view5_1.html')

@app.route('/view5_2')
def view5_2():
    guimo = list(data1['公司规模'].unique())
    guimo = custom_sort(guimo)
    guimo_count = list(data1['公司规模'].value_counts())
    shu = [i / 12229 for i in guimo_count]
    mid_np = np.array(shu)
    mid_np_2f = np.round(mid_np, 2)
    c = (
        EffectScatter()
            .add_xaxis(guimo)
            .add_yaxis("", guimo_count, symbol=SymbolType.ARROW)
            .set_global_opts(title_opts=opts.TitleOpts(title="公司规模的数量"))
        #     .render("effectscatter_symbol.html")
    )
    c.render('templates/view5_2.html')
    return render_template('view5_2.html')



@app.route('/view6')
def view6():
    return  render_template('view6.html')


@app.route('/view6_1')
def view6_1():
    company_rank = data1[['职位名称', '公司名称', '薪资均值', '公司规模']].groupby(['公司名称', '公司规模', '职位名称']).mean(). \
        sort_values(by=['薪资均值'], ascending=False).reset_index()
    table = Table()
    table_rows = [company_rank.iloc[i, :].tolist() for i in range(50)]
    table.add(company_rank.columns.tolist(), table_rows)
    table.render('templates/view6_1.html')
    return render_template('view6_1.html')









if __name__ == '__main__':
    app.run(debug=True)
